package com.zlt.appparking.controller;

import com.zlt.appparking.entity.VipType;
import com.zlt.appparking.service.MemberService;
import com.zlt.appparking.vo.CouponVO;
import com.zlt.appparking.vo.ParkingLotVO;
import com.zlt.appparking.vo.Result;
import com.zlt.appparking.vo.VIPVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("member")
public class MemberController {


    @Autowired
    private MemberService memberService;


    /**
     * 查询vip类型
     * @param id  停车场id
     * @return
     */
    @GetMapping("vipType")
    public Result vipType(Integer id){
        List<VIPVO> vipvos = memberService.vipType(id);
        return Result.ok("查询成功",vipvos);
    }

    /**
     * 根据停车场名字模糊查找对应的停车场
     * @param name
     * @return
     */
    @PostMapping("parking")
    public Result parking(String name){

        List<ParkingLotVO> parkingLotVOList = memberService.selectParking(name);
        return Result.ok("查询成功",parkingLotVOList);

    }

    /**
     * 开通会员
     * @param vtId vip类型
     * @param month 开通几个月
     * @param plId 停车场vip对应的停车场id
     * @return
     */
    @PostMapping("open")
    public Result open(Integer vtId,Integer month,Integer plId,String payType){

        String success = memberService.open(vtId,month,plId,payType);
        if ("true".equals(success)){
            return Result.ok("开通成功");
        }else if("false".equals(success)){
            return Result.error("开通失败");
        }
        return Result.ok("订单已生成",success);
    }

    /**
     * 查看会员到期时间
     * @return
     */
    @PostMapping("time")
    public Result vipTime(){
        List<VIPVO> vip = memberService.selectTime();
        return Result.ok("查询成功",vip);
    }


    /**
     * 查看有效期内的优惠券
     * @return
     */
    @PostMapping("coupons")
    public Result coupons(){
        List<CouponVO> couponVOS = memberService.coupons();
        return Result.ok("查询成功",couponVOS);
    }


    /**
     * 查看已使用/已失效的优惠券
     * @return
     */
    @PostMapping("overdueCoupons")
    public Result overdueCoupons(){
        List<CouponVO> couponVOS = memberService.overdueCoupons();
        return Result.ok("查询成功",couponVOS);
    }


    /**
     * 查询具体停车场折扣
     * @param pName 停车场名称
     * @return
     */
    @PostMapping("discount")
    public Result discount(String pName){
        List<VIPVO> vipVOList = memberService.getDiscount(pName);
        return Result.ok("查询成功",vipVOList);
    }

}
